/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.duduso.conferencia_claro_desktop.utils;

import org.apache.commons.mail.EmailAttachment;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.MultiPartEmail;
import org.apache.commons.mail.SimpleEmail;

/**
 *
 * @author duduso
 */
public class EnviarEmail {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        try {

//                SimpleEmail yahooMail = getYahooMail();
//                yahooMail.send();

//                SimpleEmail gmail = getGmail();
//                gmail.send();

                MultiPartEmail gmailAnexo = getGmailAnexo();
                gmailAnexo.send();

        } catch (EmailException ex) {

                System.out.println("Erro ao Tentar Enviar E-mail: " + ex);

        }

    }

    private static SimpleEmail getYahooMail() throws EmailException{

            SimpleEmail email = new SimpleEmail();

            email.setHostName("smtp.mail.yahoo.com.br"); // o servidor SMTP para envio do e-mail

            email.setSmtpPort(587);

            email.setAuthentication("elaine_oliveira18", "221206");

            email.addTo("duduso2004@yahoo.com.br", "Eduardo Santos de Oliveira"); //destinatário

            email.setFrom("elaine_oliveira18@yahoo.com.br", "Elaine Aparecida de Oliveira"); // remetente

            email.setSubject("Mensagem de Teste"); // assunto do e-mail

            email.setMsg("Teste de Email utilizando commons-email"); //conteudo do e-mail

            return email;

    }

    private static SimpleEmail getGmail() throws EmailException{

            SimpleEmail email = new SimpleEmail();

            email.setHostName("smtp.gmail.com"); 

            email.setSmtpPort(587);

            email.setAuthentication("elaine.oliveira@grupolagoa.com.br", "2212@du");

            email.addTo("duduso2004@yahoo.com.br", "Eduardo Santos de Oliveira");

            email.setFrom("elaine.oliveira@grupolagoa.com.br", "Elaine Aparecida de Oliveira"); 

            email.setSubject("Mensagem de Teste"); 

            email.setMsg("Teste de Email utilizando commons-email"); 

            email.setSSL(true);

            return email;

    }


    private static MultiPartEmail getGmailAnexo() throws EmailException{

            EmailAttachment attachment = new EmailAttachment();

            attachment.setPath("/home/duduso/CMTandGlassFish-SB-041709-LR.pdf"); 

            attachment.setDisposition(EmailAttachment.ATTACHMENT);

            attachment.setDescription("Anexo de Testes");

            attachment.setName("Anexo de Testes");

            MultiPartEmail email = new MultiPartEmail();

            email.setHostName("smtp.gmail.com");

            email.setSmtpPort(587);

            email.setAuthentication("elaine.oliveira@grupolagoa.com.br", "2212@du");

            email.addTo("duduso2004@yahoo.com.br", "Eduardo Santos de Oliveira");

            email.setFrom("elaine.oliveira@grupolagoa.com.br", "Elaine Aparecida de Oliveira");

            email.setSubject("Mensagem de Teste");

            email.setMsg("Teste de Email utilizando commons-email");

            email.setSSL(true);

            email.attach(attachment);

            return email;

    }

}
